package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Util {
	private static String Driver;
	private static String url;
	private static Connection con;
	private static String user;
	private static String password;

	private Util() {

	}

	static {
		Driver = "oracle.jdbc.driver.OracleDriver";
		url = "jdbc:oracle:thin:@127.0.0.1:1521:xe";
		user = "hr";
		password = "123";
		try {
			Class.forName(Driver);
			con = DriverManager.getConnection(url, user, password);

		} catch (ClassNotFoundException e) {

			e.printStackTrace();
		} catch (SQLException e) {

			e.printStackTrace();
		}

	}

	public static Connection getCon() {
		return con;
	}

	public static void close(Statement stm) {
		try {
			stm.close();
			con.close();
		} catch (SQLException e) {

			e.printStackTrace();
		}
	}

	public static void close(PreparedStatement pstm) {
		try {
			pstm.close();
			con.close();
		} catch (SQLException e) {

			e.printStackTrace();
		}
	}

	public static void close(ResultSet rs) {
		try {
			rs.close();
		} catch (SQLException e) {

			e.printStackTrace();
		}
	}
}
